package com.itheima.JDBC.demo;

import com.mysql.jdbc.Driver;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class demo01 {
    public static void main(String[] args) throws Exception {

        //注册驱动
        DriverManager.registerDriver(new Driver());
        //获取链接对象
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/heima", "root", "root");
        //根根连接对象 ，获取可以执行的sql语句的对象
        Statement statement = connection.createStatement();
        String sql = "select *from emp";
        //执行具体 的sql语句，获取操作集
        ResultSet resultSet = statement.executeQuery(sql);

        //
        while (resultSet.next()) {
            String ename = resultSet.getString("ename");
            System.out.println(ename);
        }

        //释放资源
        resultSet.close();
        statement.close();
        connection.close();
    }
}
